﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Enterprise.Framework.Frame.Architecture;
using Resto.CostControl.Core.Query.SiteModule.ViewObject;
using Enterprise.Framework.DomainModel.Repositories;
using Resto.CostControl.Core.Domain.Model;
using Enterprise.Framework.DomainModel.Specifications;
using Enterprise.Framework.DomainModel;

namespace Resto.CostControl.Core.Query.SiteModule.QueryObject
{
    public class SiteIncomeQO : IApplicationQueryObject
    {
        private IQueryable<SiteIncomeVO> GetSiteIncomeVOSet()
        {
            IEntityRepository<SiteIncome> repository = RestoCostDomainSession.CurrentSession.CreateEntityRepository<SiteIncome>();

            IQueryable<SiteIncomeVO> list = from o in repository.Objects
                                            select new SiteIncomeVO()
                                            {
                                                ID = o.ID,
                                                Date = o.Date,
                                                TotalAmount = o.TotalAmount,
                                                SiteId = o.SiteID,
                                                StateCode = o.State,
                                            };

            return list;
        }

        public SiteIncomeVO[] QuerySiteIncomeVOByPager(ISpecification<SiteIncomeVO> spec, PagerCondition pager, string orderKey, bool isAscending)
        {
            IQueryable<SiteIncomeVO> list = GetSiteIncomeVOSet();

            if (spec != null)
                list = list.Where(spec.GetExpression());

            IEnumerable<SiteIncomeVO> list2 = RepositoryExtention.Query(list, pager, orderKey, isAscending);
            return list2.ToArray();
        }
    }
}
